package com.cwd.arm.application.service.write;

import com.cwd.arm.application.dto.ReceiveRecordDto;
import com.cwd.arm.application.dto.receiveRecord.ReceiveRecordAddDto;
import com.cwd.arm.application.dto.receiveRecord.ReceiveRecordUpdateDto;
import com.cwd.arm.application.service.write.facade.ReceiveRecordWriteService;
import com.cwd.arm.domain.entity.ReceiveRecordEntity;
import com.cwd.arm.domain.repository.ProjectRepository;
import com.cwd.arm.domain.repository.ReceiveNodeRepository;
import com.cwd.arm.domain.repository.ReceiveRecordRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
* Description:收款记录
* Created on 2021年11月16日
* @author  yan
*/
@Repository
@Primary
public class ReceiveRecordWriteServiceImpl implements ReceiveRecordWriteService{

    @Autowired
    private ReceiveRecordRepository receiveRecordRepository;


    @Transactional
    @Override
    public void save(ReceiveRecordAddDto addDto) {
        receiveRecordRepository.save(convertToEntity(addDto));
    }

    @Transactional
    @Override
    public void update(ReceiveRecordUpdateDto updateDto) {
        receiveRecordRepository.update(convertToEntity(updateDto));
    }

    @Transactional
    @Override
    public void del(Long id) {
        receiveRecordRepository.del(id);
    }

    private ReceiveRecordEntity convertToEntity(ReceiveRecordAddDto dto){
        ReceiveRecordEntity receiveRecordEntity = new ReceiveRecordEntity();
        BeanUtils.copyProperties(dto,receiveRecordEntity);
        return receiveRecordEntity;
    }

    private ReceiveRecordEntity convertToEntity(ReceiveRecordUpdateDto dto){
        ReceiveRecordEntity receiveRecordEntity = new ReceiveRecordEntity();
        BeanUtils.copyProperties(dto,receiveRecordEntity);
        return receiveRecordEntity;
    }
}
